# Maintainer: Philipp Smirnov https://github.com/sad-poet

_realname=libadalang-tools
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=25.0.0
pkgrel=2
pkgdesc="Libadalang-based tools for Ada: gnatpp, gnatmetric, gnatstub and gnattest (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
url="https://github.com/AdaCore/libadalang-tools"
msys2_references=(
  'aur: libadalang-tools'
  'gentoo: dev-ada/libadalang-tools'
)
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libadalang"
         "${MINGW_PACKAGE_PREFIX}-gcc-ada"
         "${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-core"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-gmp"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-iconv"
         "${MINGW_PACKAGE_PREFIX}-gpr"
         "${MINGW_PACKAGE_PREFIX}-langkit_support"
         "${MINGW_PACKAGE_PREFIX}-libgpr"
         "${MINGW_PACKAGE_PREFIX}-templates-parser"
         "${MINGW_PACKAGE_PREFIX}-xmlada")
makedepends=("${MINGW_PACKAGE_PREFIX}-gprbuild")
source=("https://github.com/AdaCore/libadalang-tools/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('18302c62ba494acff57acfa701861e6e41110a8902f5cc3c612863707c934e3c')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}/"
  build_year=$(LANG=C date "+%Y")
  sed -i 's/:= "dev";/:= "'"${pkgver}"'";/' "src/utils-versions.ads"
  sed -i 's/:= "unknown";/:= "'"${build_year}"'";/' "src/utils-versions.ads"
}

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}"/build-${MSYSTEM}
  cd "${srcdir}"/build-${MSYSTEM}

  BUILD_MODE=prod \
  LIBRARY_TYPE=relocatable \
  make lib bin
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}

  BUILD_MODE=prod \
  LIBRARY_TYPE=relocatable \
  make DESTDIR="${pkgdir}${MINGW_PREFIX}" install-lib install-bin-strip

  install -Dm644 -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}" \
    "${srcdir}/${_realname}-${pkgver}"/LICENSE
}
